function setPosition(obj, _x, _y)
	obj.x = _x
	obj.y = _y
end

function move(x, y, angle, speed)

	tempx = x + (math.cos(angle) * speed)
	tempy = y + (math.sin(angle) * speed)
	return tempx,tempy
end

function calculateAngle(x1, y1, x2, y2)
	--temp = math.atan( ( ((v.path[1].y - v.y)) / (v.path[1].x - v.x)) )
	temp = math.atan(  (y2 - y1) / (x2 - x1) ) 

	if x2 < x1 then
		temp = temp + math.pi
	end

	return temp
end

--takes objects and uses their x,y instead of just taking in an x and y. this helps readability
function calculateAngleObj(a,b)
	
	if a == nil or b == nil then
		return -1
	end
	
	--temp = math.atan( ( ((v.path[1].y - v.y)) / (v.path[1].x - v.x)) )
	temp = math.atan(  (b.y - a.y) / (b.x - a.x) ) 

	if b.x < a.x then
		temp = temp + math.pi
	end

	return temp
end

function getDistance(x1, y1, x2, y2)
	return math.sqrt( ((x2-x1)^2) + ((y2-y1)^2) )
end

--takes objects and uses their x,y instead of just taking in an x and y. this helps readability
function getDistanceObj(a,b)
	if a == nil or b == nil then
		return -1
	end

	return math.sqrt( ((b.x-a.x)^2) + ((b.y-a.y)^2) )
end

function squareCollisionObj(obj,sqr,r)
	if r == nil then
		if obj.x > sqr.x and obj.x < sqr.x2 and obj.y > sqr.y and obj.y < sqr.y2 then
			return true
		else
			return false
		end	
	end
end

function goodPoint(x, y, pointDist, clearPath)
    for i,v in ipairs(terrain) do
        -- If the point is within a square, it is not valid.
        if ((v.x - 5 <= x  and x <= v.x+v.w + 5) and (v.y - 5 <= y and y <= v.h + v.y + 5)) then 
            return false;
        end
    end
	if not clearPath then
		for i,v in ipairs(waypoints) do
			if self ~= v and getDistance(x, y, v.x, v.y) < pointDist then
				return false
			end
			if  x < 0 or y < 0 then
				return false
			end
		end
	end
	return true;
end

-- check to see if all points on the line are good points
function goodLine(x1, y1, x2, y2, pointDist)
	if x1 == x2 then
		if y1 == y2 then return goodPoint(x1, y1, pointDist, true) end
		if y1 < y2 then
			for i=y1+1, y2 do
				if not goodPoint(x1, i, pointDist, true) then
					return false
				end
			end
		else
			for i=y2+1, y1 do
				if not goodPoint(x1, i, pointDist, true) then
					return false
				end
			end
		end
		return true
	end
	if x1 < x2 then
		for i=x1+1,x2 do
			local y = (y1 + ((y2-y1)/(x2-x1))*(i-x1))
			if not goodPoint(i, y, pointDist, true) then
				return false
			end
		end
	else
		for i=x2+1,x1 do
			local y = y1 + ((y2-y1)/(x2-x1))*(i-x1)
			if not goodPoint(i, y, pointDist, true) then
				return false
			end
		end
	end
	return true
end